package com.qn.config;

import com.baidu.aip.contentcensor.AipContentCensor;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 审核邮件内容配置
 */
public class AipContentCensorSelfConfig {
    //设置APPID/AK/SK
    public static final String APP_ID = "24529056";
    public static final String API_KEY = "wfdXCHhHLzaUlZf9HskqKO42";
    public static final String SECRET_KEY = "YdaZVrse5sQATC5qDjN0t0CUeOf0HjIO";
    /**
     * 日志对象
     */
    private static final Logger log = LoggerFactory.getLogger(AipContentCensorSelfConfig.class);

    public static Map<String, Object> checkContext(String text) {
        // 初始化一个AipContentCensor
        AipContentCensor client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);
        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        // 可选：设置log4j日志输出格式，若不设置，则使用默认配置
        // 也可以直接通过jvm启动参数设置此环境变量
        System.setProperty("aip.log4j.conf", "log4j.properties");
        // 调用接口
        JSONObject res = client.textCensorUserDefined(text);
        log.info("审核结果:" + res.toString(2));
        return res.toMap();
    }
}
